package com.dh.example.netty.controller;

import com.dh.example.netty.service.WebSocketService;
import com.dh.example.netty.util.WsMsgBuilderAdapter;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author yolo
 * @date 2024/3/20 16:39
 * @mail yolo_215@163.com
 */

@RestController
@RequestMapping("/")
public class TestController {

    @Resource
    private WebSocketService webSocketService;

    @GetMapping("/send")
    public void send(Long userId, String message) {
        webSocketService.sendToUid(WsMsgBuilderAdapter.buildSystemMsgResp(message), userId);
    }

    @GetMapping("/sendAll")
    public void sendAll(String message) {
        webSocketService.sendToAllOnline(WsMsgBuilderAdapter.buildSystemMsgResp(message));
    }
}
